export function findSubsequences(nums: number[]): number[][] {
    const ret: number[][] = [];
    const path: number[] = [];

    backTrace(0, nums, path, ret);

    return ret;
};

function backTrace (startIndex: number ,nums: number[], path: number[], ret: number[][]) {

    // 只要 path 中元素大于1，就加入结果集
    if (path.length > 1) {
        ret.push([...path]);
    }

    const set = new Set<number>();
    for (let i = startIndex; i < nums.length; i++) {
        // 剪枝
        // 如果当前元素小于 path 中最后一个元素
        if ((path.length > 0) && (nums[i] < path[path.length-1])) {
            continue;
        }
        // 如果在本层已经出现过，则跳过
        if (set.has(nums[i])) {
            continue;
        }

        set.add(nums[i]);
        // 回溯
        path.push(nums[i]);
        backTrace(i+1, nums, path, ret);
        path.pop();
    }
}